package com.hhit.collaborative_learning.learning;

import java.io.IOException;
import java.util.Calendar;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hhit.collaborative_learning.dao.impl.PublicDaoImplMySql;
import com.hhit.collaborative_learning.entity.BlogPage;
import com.hhit.collaborative_learning.utils.Utils;
import com.mysql.jdbc.StringUtils;

public class GetBlogServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String type = request.getParameter("type");
		String currentPage = request.getParameter("currentPage");
		String orderBy=request.getParameter("orderby");
		if(StringUtils.isNullOrEmpty(currentPage)||currentPage.equals("1")){
			Calendar now = Calendar.getInstance();
			Utils.now = now;
			Utils.getSomedaysAgo(now);
		}
		HttpSession session=request.getSession();
		PublicDaoImplMySql dao=new PublicDaoImplMySql();
		type=StringUtils.isNullOrEmpty(type)?"all":type;
		BlogPage blogPage=dao.getBlog(type, currentPage, orderBy);
		request.setAttribute("blogPage", blogPage);
		request.setAttribute("type", type);
		request.setAttribute("orderby", orderBy);
		
//		if (StoreData.twoDaysBlog.isEmpty()) {
			StoreData.getBlog(1);
//		}
//		if (session.getAttribute("twoDays") == null&&!StoreData.twoDaysBlog.isEmpty()) {
			request.setAttribute("twoDays", StoreData.twoDaysBlog);
//		}
//
//		if (StoreData.newestRecommendBlog.isEmpty()) {
			StoreData.getBlog(2);
//		}
//		if (session.getAttribute("newestRec") == null&&!StoreData.newestRecommendBlog.isEmpty()) {
			request.setAttribute("newestRec", StoreData.newestRecommendBlog);
//		}
//
//		if (StoreData.expertList == null) {
//			StoreData.getExperts();
//		}
//		if (session.getAttribute("experts") == null) {
//			session.setAttribute("experts", StoreData.expertList);
//		}

//		if (StoreData.newestExperts.isEmpty()) {
//			StoreData.getNewestExperts();
//		}
//		if (session.getAttribute("newestExpert") == null&&!StoreData.newestExperts.isEmpty()) {
//			session.setAttribute("newestExpert", StoreData.newestExperts);
//		}

//		if (StoreData.primeBlog.isEmpty()) {
//			StoreData.getPrimeBlog();
//		}
//		if (session.getAttribute("primeBlog") == null&&!StoreData.primeBlog.isEmpty()) {
//			session.setAttribute("primeBlog", StoreData.primeBlog);
//		}
		
		request.getRequestDispatcher("learning/category.jsp").forward(request, response);
//		if (type.equals("all")||StringUtils.isNullOrEmpty(type)) {
//		} else if (type.equals("mobile")) {
//			if (currentPage == null) {
//
//			} else {
//
//			}
//		} else if (type.equals("web")) {
//			if (currentPage == null) {
//
//			} else {
//
//			}
//		} else if (type.equals("enterprise")) {
//			if (currentPage == null) {
//
//			} else {
//
//			}
//		} else if (type.equals("code")) {
//			if (currentPage == null) {
//
//			} else {
//
//			}
//		} else if (type.equals("www")) {
//			if (currentPage == null) {
//
//			} else {
//
//			}
//		} else if (type.equals("database")) {
//			if (currentPage == null) {
//
//			} else {
//
//			}
//		} else if (type.equals("system")) {
//			if (currentPage == null) {
//
//			} else {
//
//			}
//		} else if (type.equals("cloud")) {
//			if (currentPage == null) {
//
//			} else {
//
//			}
//		} else if (type.equals("software")) {
//			if (currentPage == null) {
//
//			} else {
//
//			}
//		} else if (type.equals("other")) {
//			if (currentPage == null) {
//
//			} else {
//
//			}
//		}
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}

}
